package com.kk.score.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * @author KK
 * @email 409592048@qq.com
 * @date 2022-11-02 12:28:00
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("user")
public class UserEntity extends SuperEntity<UserEntity> implements UserDetails {
    private static final long serialVersionUID = 1L;


    /**
     * 部门uid
     */
    private String departmentUid;

    /**
     * 职位uid
     */
    private String positionUid;

    /**
     * 姓名
     */
    private String name;

    /**
     * 性别
     */
    private String sex;

    /**
     * 工号
     */
    @NotNull(message = "请输入工号！")
    @NotEmpty(message = "请输入工号！")
    @NotBlank(message = "请输入工号！")
    private String username;

    /**
     * 密码
     */
    @NotNull(message = "请输入密码！")
    @NotEmpty(message = "请输入密码！")
    @NotBlank(message = "请输入密码！")
    private String password;


    /**
     * 0=评分，1=满意度
     */
    private Integer isGrade;

    public UserEntity(String uid, int status) {
        setUid(uid);
        setStatus(status);
    }

    public UserEntity(String uid, String password) {
        setUid(uid);
        setPassword(password);
    }

    public String getUsername() {
        return this.username;
    }

    public String getPassword() {
        return this.password;
    }

    /**
     * 权限
     */
    @TableField(exist = false)
    @JsonIgnore
    private Set<GrantedAuthority> authorities;

    @Override
    @JsonIgnore
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    @JsonIgnore
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    @JsonIgnore
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    @JsonIgnore
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    @JsonIgnore
    public boolean isEnabled() {
        return true;
    }
}
